home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glider 3.14 / source / Glider parts ƒ / C-Dialogs.p < prev    next >
Encoding:
Text File  |  1991-04-30  |  12.8 KB  |  295 lines  |  [TEXT/PJMM]

  1. unit Dialogs;
  2.  
  3. interface
  4.  
  5.     procedure D_BeginWhere (var levelBegin: Integer);
  6.     procedure D_Controls (var leftControl, rightControl: Char);
  7.     procedure D_Number_of_Gliders (var gliderStart: Integer);
  8.     procedure WhosHiScore (var theName: Str255);
  9.  
  10. implementation
  11.  
  12.     const                                   {These are the item numbers for controls in the Dialog}
  13.         I_Okay = 1;
  14.         I_Static_Text = 2;
  15.         I_Static_Text3 = 3;
  16.         I_Edit_Text = 4;
  17.         I_Edit_Text6 = 5;
  18.  
  19.     var
  20.         ExitDialog: boolean;                        {Flag used to exit the Dialog}
  21.         GetSelection: DialogPtr;                    {Name of dialog}
  22.         tempRect: Rect;                            {Temporary rectangle}
  23.         DType: Integer;                            {Type of dialog item}
  24.         Index: Integer;                            {For looping}
  25.         iTemp: LongInt;
  26.         DItem: Handle;                            {Handle to the dialog item}
  27.         CItem, CTempItem: controlhandle;        {Control handle}
  28.         sTemp: Str255;                            {Get text entered, temp holding    }
  29.         cTemp: Char;
  30.         itemHit: Integer;                            {Get selection}
  31.         temp: Integer;                            {Get selection, temp holding}
  32.         ThisEditText: TEHandle;                    {Handle to get the Dialogs TE record}
  33.         TheDialogPtr: DialogPeek;                {Pointer to Dialogs definition record, contains the TE record}
  34.  
  35. {=========================================}
  36.  
  37.     procedure D_BeginWhere;
  38.  
  39.         procedure Refresh_Dialog;               {Refresh the dialogs non-controls}
  40.             var
  41.                 rTempRect: Rect;                       {Temp rectangle used for drawing}
  42.         begin
  43.             PenNormal;
  44.             GetDItem(GetSelection, I_Okay, DType, DItem, tempRect);{Get the item handle}
  45.             PenSize(3, 3);                  {Change pen to draw thick default outline}
  46.             InsetRect(tempRect, -4, -4);        {Draw outside the button by 1 pixel}
  47.             FrameRoundRect(tempRect, 16, 16); {Draw the outline}
  48.             PenSize(1, 1);
  49.         end;
  50.  
  51.     begin                                   {Start of dialog handler}
  52.         GetSelection := GetNewDialog(7, nil, Pointer(-1)); {Bring in the dialog resource}
  53.         tempRect := GetSelection^.portRect;    {Get window size, we will now center it}
  54.         tempRect.Top := ((screenBits.Bounds.Bottom - screenBits.Bounds.Top) - (tempRect.Bottom - tempRect.Top)) div 2;
  55.         tempRect.Left := ((screenBits.Bounds.Right - screenBits.Bounds.Left) - (tempRect.Right - tempRect.Left)) div 2;
  56.         MoveWindow(GetSelection, tempRect.Left, tempRect.Top, TRUE);{Now move the window to the proper position}
  57.         ShowWindow(GetSelection);            {Open a dialog box}
  58.         SelectWindow(GetSelection);        {Lets see it}
  59.         SetPort(GetSelection);                {Perpare to add conditional text}
  60.   {Setup initial conditions}
  61.         GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect);{Get item handle}
  62.         NumToString(levelBegin, sTemp);
  63.         SetIText(DItem, sTemp);            {Set the default text string}
  64.         SelIText(GetSelection, I_Edit_Text, 0, 2);
  65.         Refresh_Dialog;
  66.         ExitDialog := FALSE;                    {Do not exit dialog handle loop yet}
  67.         repeat
  68.             ModalDialog(nil, itemHit);            {Wait until an item is hit}
  69.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect);        {Get item information    }
  70.             CItem := Pointer(DItem);                {Get the control handle                                    }
  71.             if (ItemHit = I_Okay) then            {Handle the Button being pressed                        }
  72.                 begin
  73.                     GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect);    {Get handle        }
  74.                     GetIText(DItem, sTemp);            {Get the text entered                                    }
  75.                     StringToNum(sTemp, iTemp);        {Covert this text into an integer first.                }
  76.                     if (iTemp >= 1) and (iTemp <= 9) then        {First, is the number in proper range?    }
  77.                         begin
  78.                             ExitDialog := TRUE;                {Exit the dialog when this selection is made            }
  79.                         end
  80.                     else
  81.                         begin
  82.                             SysBeep(1);                         {Whoops, they're breaking the rules (or trying to)}
  83.                             SysBeep(1);                        {Two beeps to you, Mr. or Ms. cheater!                }
  84.                             NumToString(levelBegin, sTemp);        {Reset to the original value                    }
  85.                             SetIText(DItem, sTemp);
  86.                         end;
  87.                 end;                                    {End for this item selected                                }
  88.         until ExitDialog;                            {Handle dialog items until exit selected                }
  89.         GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect);    {Get the item handle    }
  90.         GetIText(DItem, sTemp);                {Get the text entered}
  91.         StringToNum(sTemp, iTemp);
  92.         levelBegin := iTemp;
  93.         DisposDialog(GetSelection);            {Flush the dialog out of memory}
  94.     end;                                            {End of procedure                                        }
  95.  
  96. {=========================================}
  97.  
  98.     procedure D_Controls;
  99.  
  100.         procedure Refresh_Dialog;               {Refresh the dialogs non-controls}
  101.             var
  102.                 tempRect: Rect;                       {Temp rectangle used for drawing}
  103.         begin
  104.             PenNormal;
  105.             GetDItem(GetSelection, I_Okay, DType, DItem, tempRect);{Get the item handle}
  106.             PenSize(3, 3);                  {Change pen to draw thick default outline}
  107.             InsetRect(tempRect, -4, -4);        {Draw outside the button by 1 pixel}
  108.             FrameRoundRect(tempRect, 16, 16); {Draw the outline}
  109.             PenSize(1, 1);
  110.         end;
  111.  
  112.     begin                                   {Start of dialog handler}
  113.         GetSelection := GetNewDialog(6, nil, Pointer(-1)); {Bring in the dialog resource}
  114.         tempRect := GetSelection^.portRect;    {Get window size, we will now center it}
  115.         tempRect.Top := ((screenBits.Bounds.Bottom - screenBits.Bounds.Top) - (tempRect.Bottom - tempRect.Top)) div 2;
  116.         tempRect.Left := ((screenBits.Bounds.Right - screenBits.Bounds.Left) - (tempRect.Right - tempRect.Left)) div 2;
  117.         MoveWindow(GetSelection, tempRect.Left, tempRect.Top, TRUE);{Now move the window to the proper position}
  118.         ShowWindow(GetSelection);                {Open a dialog box}
  119.         SelectWindow(GetSelection);            {Lets see it}
  120.         SetPort(GetSelection);                    {Perpare to add conditional text}
  121.   {Setup initial conditions}
  122.         GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect); {Get the item handle}
  123.         SetIText(DItem, leftControl);            {Set the default text string}
  124.         GetDItem(GetSelection, I_Edit_Text6, DType, DItem, tempRect); {Get the item handle}
  125.         SetIText(DItem, rightControl);            {Set the default text string}
  126.         SelIText(GetSelection, I_Edit_Text6, 0, 2);
  127.         Refresh_Dialog;
  128.         ExitDialog := FALSE;                    {Do not exit dialog handle loop yet}
  129.         repeat                                {Start of dialog handle loop}
  130.             ModalDialog(nil, itemHit);          {Wait until an item is hit}
  131.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect); {Get item information}
  132.             CItem := Pointer(DItem);            {Get the control handle}
  133. {Handle it real time}
  134.             if (ItemHit = I_Okay) then           {Handle the Button being pressed}
  135.                 begin
  136.                     GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect); {Get the item handle}
  137.                     GetIText(DItem, sTemp);
  138.                     cTemp := COPY(sTemp, 1, 1);
  139.                     if (ORD(cTemp) < 127) and (ORD(cTemp) > 31) then
  140.                         begin
  141.                             ExitDialog := TRUE;
  142.                         end
  143.                     else
  144.                         begin
  145.                             SysBeep(1);
  146.                             SysBeep(1);
  147.                             SetIText(DItem, leftControl);
  148.                         end;
  149.                     GetDItem(GetSelection, I_Edit_Text6, DType, DItem, tempRect);
  150.                     GetIText(DItem, sTemp);
  151.                     cTemp := Copy(sTemp, 1, 1);
  152.                     if (Ord(cTemp) < 127) and (Ord(cTemp) > 31) then
  153.                         begin
  154.                             ExitDialog := TRUE;
  155.                         end
  156.                     else
  157.                         begin
  158.                             SysBeep(1);
  159.                             SysBeep(1);
  160.                             SetIText(DItem, rightControl);
  161.                         end;
  162.                 end;                                {End for this item selected}
  163.         until ExitDialog;                     {Handle dialog items until exit selected}
  164.  {Get results after dialog}
  165.         GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect); {Get the item handle}
  166.         GetIText(DItem, sTemp);
  167.         leftControl := Copy(sTemp, 1, 1);
  168.         GetDItem(GetSelection, I_Edit_Text6, DType, DItem, tempRect); {Get the item handle}
  169.         GetIText(DItem, sTemp);
  170.         rightControl := Copy(sTemp, 1, 1);
  171.         DisposDialog(GetSelection);           {Flush the dialog out of memory}
  172.     end;                                    {End of procedure}
  173.  
  174. {=========================================}
  175.  
  176.     procedure D_Number_of_Gliders;
  177.  
  178.         procedure Refresh_Dialog;               {Refresh the dialogs non-controls}
  179.             var
  180.                 rTempRect: Rect;                       {Temp rectangle used for drawing}
  181.         begin
  182.             PenNormal;
  183.             GetDItem(GetSelection, I_Okay, DType, DItem, tempRect);{Get the item handle}
  184.             PenSize(3, 3);                  {Change pen to draw thick default outline}
  185.             InsetRect(tempRect, -4, -4);        {Draw outside the button by 1 pixel}
  186.             FrameRoundRect(tempRect, 16, 16); {Draw the outline}
  187.             PenSize(1, 1);
  188.         end;
  189.  
  190.     begin
  191.         GetSelection := GetNewDialog(5, nil, Pointer(-1)); {Bring in the dialog resource}
  192.         tempRect := GetSelection^.portRect;    {Get window size, we will now center it}
  193.         tempRect.Top := ((screenBits.Bounds.Bottom - screenBits.Bounds.Top) - (tempRect.Bottom - tempRect.Top)) div 2;
  194.         tempRect.Left := ((screenBits.Bounds.Right - screenBits.Bounds.Left) - (tempRect.Right - tempRect.Left)) div 2;
  195.         MoveWindow(GetSelection, tempRect.Left, tempRect.Top, TRUE);{Now move the window to the proper position}
  196.         ShowWindow(GetSelection);            {Open a dialog box}
  197.         SelectWindow(GetSelection);        {Lets see it}
  198.         SetPort(GetSelection);                {Perpare to add conditional text}
  199.  
  200.         GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect);
  201.         NumToString(gliderStart, sTemp);
  202.         SetIText(DItem, sTemp);                {Set the default text string}
  203.         SelIText(GetSelection, I_Edit_Text, 0, 2);
  204.         Refresh_Dialog;
  205.         ExitDialog := FALSE;                    {Do not exit dialog handle loop yet}
  206.         repeat                                {Start of dialog handle loop}
  207.             ModalDialog(nil, itemHit);            {Wait until an item is hit}
  208.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect); {Get item information}
  209.             CItem := Pointer(DItem);            {Get the control handle}
  210.             if (ItemHit = I_Okay) then        {Handle the Button being pressed}
  211.                 begin
  212.                     GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect); {Get the item handle}
  213.                     GetIText(DItem, sTemp);        {Get the text entered}
  214.                     StringToNum(sTemp, iTemp);
  215.                     if (iTemp >= 1) and (iTemp <= 6) then
  216.                         begin
  217.                             gliderStart := iTemp;
  218.                             ExitDialog := TRUE;        {Exit the dialog when this selection is made}
  219.                         end
  220.                     else
  221.                         begin
  222.                             SysBeep(1);
  223.                             SysBeep(1);
  224.                             NumToString(gliderStart, sTemp);
  225.                             SetIText(DItem, sTemp);    {Set the default text string}
  226.                         end;
  227.                 end;                                {End for this item selected}
  228.         until ExitDialog;                        {Handle dialog items until exit selected}
  229.         DisposDialog(GetSelection);            {Flush the dialog out of memory}
  230.     end;
  231.  
  232. {===========================================}
  233.  
  234.     procedure WhosHiScore;
  235.         var
  236.             excessSpace: Integer;
  237.             dotFiller, space: Str255;
  238.  
  239.         procedure Refresh_Dialog;                {This draws the rounded-rectangular}
  240.             var                                            {border around the Okay button so that}
  241.                 rTempRect: Rect;                        {the user knows it is the default button.}
  242.         begin
  243.             PenNormal;
  244.             GetDItem(GetSelection, I_Okay, DType, DItem, tempRect);{Get the item handle}
  245.             PenSize(3, 3);                  {Change pen to draw thick default outline}
  246.             InsetRect(tempRect, -4, -4);        {Draw outside the button by 1 pixel}
  247.             FrameRoundRect(tempRect, 16, 16); {Draw the outline}
  248.             PenSize(1, 1);
  249.         end;
  250.  
  251.     begin                                                {Start of dialog handler}
  252.         GetSelection := GetNewDialog(999, nil, Pointer(-1));{Bring in the dialog resource}
  253.         tempRect := GetSelection^.portRect;    {Get window size, we will now center it}
  254.         tempRect.Top := ((screenBits.Bounds.Bottom - screenBits.Bounds.Top) - (tempRect.Bottom - tempRect.Top)) div 2;
  255.         tempRect.Left := ((screenBits.Bounds.Right - screenBits.Bounds.Left) - (tempRect.Right - tempRect.Left)) div 2;
  256.         MoveWindow(GetSelection, tempRect.Left, tempRect.Top, TRUE);{Now move the window to the proper position}
  257.         ShowWindow(GetSelection);                        {Open a dialog box}
  258.         SelectWindow(GetSelection);                    {Lets see it}
  259.         SetPort(GetSelection);                            {Perpare to add conditional text}
  260.  
  261.         GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect);
  262.         SetIText(DItem, theName);                        {Set the default text string}
  263.         SelIText(GetSelection, I_Edit_Text, 0, 15);
  264.         ExitDialog := FALSE;                                {Do not exit dialog handle loop yet}
  265.         Refresh_Dialog;
  266.         repeat                                            {Start of dialog handle loop}
  267.             ModalDialog(nil, itemHit);                        {Wait until an item is hit}
  268.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect); {Get item information}
  269.             CItem := Pointer(DItem);                        {Get the control handle}
  270.             if (ItemHit = I_Okay) then                    {Handle the Button being pressed}
  271.                 begin
  272.                     GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect); {Get the item handle}
  273.                     GetIText(DItem, sTemp);                    {Get the text entered}
  274.                     if (LENGTH(sTemp) > 15) then            {Make sure it's less than 15 characters}
  275.                         theName := COPY(sTemp, 1, 15)        {Just clip the first 15 if it is too long}
  276.                     else
  277.                         begin
  278.                             if (LENGTH(sTemp) < 15) then
  279.                                 begin
  280.                                     space := '               ';
  281.                                     excessSpace := 15 - LENGTH(sTemp);
  282.                                     dotFiller := COPY(space, 1, excessSpace);
  283.                                     sTemp := CONCAT(sTemp, dotfiller);
  284.                                 end;
  285.                             theName := sTemp;                            {Otherwise, take it as is}
  286.                         end;
  287.                     ExitDialog := TRUE;                                {Exit the dialog when this selection is made}
  288.                 end;                                                {End for this item selected}
  289.         until ExitDialog;                                        {Handle dialog items until exit selected}
  290.         DisposDialog(GetSelection);                        {Flush the dialog out of memory}
  291.     end;                                                        {End of procedure}
  292.  
  293. {===========================================}
  294.  
  295. end.                                    {End of unit}